import {Page} from '@/base/Page';
import {Prize} from '@/base/model/Prize';
import {deleteWish, selectWishes, PutWishes} from '@/base/api/BannersApi';
import {getPrizeList} from '@/base/api/ActivityApi';

class Form {
 PrizeName = '';
 IsValue = 0;
}

export class PrizeBloc {
  form = new Form();
  paged: Page<Prize> = new Page<Prize>([], 0, 1, 15, 0, []);
  loading = false;
  type: string | undefined;
  logintype: string | undefined;
  load(pageIndex: number, pageSize: number, id:number) {
    this.loading = true;
    return getPrizeList({
      pageIndex,
      pageSize,
      sortDirection: 'DESC',
      ActivityId: id
    }).then((res) => {
      this.paged = res.data;
    }).finally(() => {
      this.loading = false;
    });
  }
  reset(id:number) {
    this.form = new Form();
    this.paged.pageIndex = 1;
    this.paged.pageSize = 15;
    this.load(this.paged.pageIndex, this.paged.pageSize, id);
  }
  removeItem(dateItem: Prize) {
    this.loading = true;
    return deleteWish({wishId: dateItem.PrizeID})
      .finally(() => {
        this.loading = false;
      });
  }

  switchStatus(id, value, index) {
    if (value) {
      this.form.IsValue = 1
    } else {
      this.form.IsValue = 0
    }
    this.modifyItem(id, this.form.IsValue)

  }

  modifyItem(
    wishId: number,
    isAble: number
  ) {
    // this.loading = true;
    // return PutWishes({
    //   wishId,
    //   isAble
    // }).then((res) => {
    //   // this.load(this.paged.pageIndex, this.paged.pageSize, this.form.routeId);
    // }).finally(() => {
    //   this.loading = false;
    // })
  }
}
